package com.lanswon.qzsmk.controller.inventoryManageController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryMagOfReturnFileImport")
public class InventoryMagOfReturnFileImportController {
	
private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryMagOfReturningByEmpController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	@RequiresPermissions("inventoryMagOfReturnFileImport:index")
	@RequestMapping(name = "制卡返回文件导入,inventoryMagOfReturnFileImport:index",value = "/importReturnFilePage", method = { RequestMethod.POST, RequestMethod.GET })
	public String importReturnFilePage(HttpServletRequest request) {
		return "ImportReturnFile";
	}

	@RequiresPermissions("inventoryMagOfReturnFileImport:addFileList")
	@RequestMapping(name = "加入文件列表,inventoryMagOfReturnFileImport:addFileList",value = "/addFileList", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String,Object> addFileList(@RequestParam("returnFilePath") MultipartFile[] returnFilePath,HttpServletRequest request) throws IllegalStateException, IOException {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		logger.debug("returnFilePath==>"+returnFilePath.toString());
		resultMap = ims.addReturnFileToPageTable(returnFilePath,request);
		logger.debug("resultMap==>"+resultMap);
		return resultMap;
	}
	
	@RequiresPermissions("inventoryMagOfReturnFileImport:importReturnFileRegister")
	@RequestMapping(name = "导入文件到系统,inventoryMagOfReturnFileImport:importReturnFileRegister",value = "/importReturnFileRegister", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String,Object> importReturnFileRegister(HttpServletRequest request) {
		ims.returnFileImportRegister(request);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("callbackType", "forward");
		map.put("forwardUrl", "inventoryMagOfReturnFileImport/importReturnFilePage");
		map.put("statusCode", "200");
		map.put("method", "GET");
		map.put("message", "导入成功");
		return map;
	}
	
	@RequiresPermissions("inventoryMagOfReturnFileImport:deleteFileList")
	@RequestMapping(name = "导入文件到系统,inventoryMagOfReturnFileImport:deleteFileList",value = "/deleteFileList", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String,Object> deleteFileList(HttpServletRequest request) {
		ims.deleteReturnFileAtRoot(request);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("statusCode", "200");
		return map;
	}
	
	@RequestMapping(value = "/exportReturnFilePage", method = { RequestMethod.POST, RequestMethod.GET })
	public String exportReturnFilePage(HttpServletRequest request) {
		return "PDF_ViewTest";
	}
}
